// Copyright (c) 2024 by Rockchip Electronics Co., Ltd. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License

#include <cmath>
#include <fstream>
#include <cmath>
#include <fstream>
#include <limits>
#include <vector>
#include "sv2_yolo11.h"

using namespace std;

// struct timeval start_time, end_time;
// float timeuse = 0.0f;
namespace sv2
{
  void YOLOv11DetCppNode_Rknn::run()
  {
    while (this->is_running())
    {   
      if (this->get_img_flag != 1)
      {
        usleep(3000);
        continue;
      }
      ImgMsg imgmsg = this->_full_queue.front();
      this->_full_queue.pop();
      this->get_img_flag = 0;
      
      // cv::imshow("imgmsg.img", imgmsg.img);
      // cv::waitKey(1);
      // printf("to send img\n");
      // gettimeofday(&start_time, NULL);
      this->_vs.stream(imgmsg.img, imgmsg.msg);
      // gettimeofday(&end_time, NULL);
      // timeuse = (end_time.tv_sec - start_time.tv_sec) * 1000 + ((float)end_time.tv_usec - start_time.tv_usec) / 1000; //ms
      // if (timeuse > 100)
      //   printf("all yolo time %0.2f\n", timeuse);
    }
  }
}
